package com.navinfo.platform.bigdata.dto;

import com.navinfo.platform.bigdata.util.EntityConvert;
import com.navinfo.stream.qingqi.protocol.java.LCLocationData.ModuleVoltage;

public class ModuleVoltagesDto {
    private int moduleNum;
    private int number;
    private float voltage;

    public int getModuleNum() {
        return moduleNum;
    }
    public void setModuleNum(int moduleNum) {
        this.moduleNum = moduleNum;
    }
    public int getNumber() {
        return number;
    }
    public void setNumber(int number) {
        this.number = number;
    }
    public float getVoltage() {
        return voltage;
    }
    public void setVoltage(float voltage) {
        this.voltage = voltage;
    }

    /**
     * 解析成String拼接字符串
     * @param moduleVoltage
     * @return
     */
    public static String parseString(ModuleVoltage moduleVoltage){
        return EntityConvert.convert(
                moduleVoltage.getModuleNum(),
                moduleVoltage.getNumber(),
                moduleVoltage.getVoltage()
        );
    }

    /**
     * 反解析成PB对象
     * @param str
     * @return
     */
    public static ModuleVoltage parsePB(String str){
        ModuleVoltage.Builder builder = null;
        try{
            String[] revert = EntityConvert.revert(str);
            if(null!=revert && revert.length>=3){
                builder = ModuleVoltage.newBuilder();
                builder.setModuleNum(Integer.valueOf(revert[0]));
                builder.setNumber(Integer.valueOf(revert[1]));
                builder.setVoltage(Float.valueOf(revert[2]));
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return builder==null? null : builder.build();
    }
}
